home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / machine / centiped.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  2KB  |  58 lines

  1. /***************************************************************************
  2.  
  3.   machine.c
  4.  
  5.   Functions to emulate general aspects of the machine (RAM, ROM, interrupts,
  6.   I/O ports)
  7.  
  8. ***************************************************************************/
  9.  
  10. #include "driver.h"
  11.  
  12. /*
  13.  * This wrapper routine is necessary because Centipede requires a direction bit
  14.  * to be set or cleared. The direction bit is held until the mouse is moved
  15.  * again.
  16.  *
  17.  * There is a 4-bit counter, and two inputs from the trackball: DIR and CLOCK.
  18.  * CLOCK makes the counter move in the direction of DIR. Since DIR is latched
  19.  * only when a CLOCK arrives, the DIR bit in the input port doesn't change
  20.  * until the trackball actually moves.
  21.  *
  22.  * There is also a CLR input to the counter which could be used by the game to
  23.  * clear the counter, but Centipede doesn't use it (though it would be a good
  24.  * idea to support it anyway).
  25.  *
  26.  * The counter is read 240 times per second. There is no provision whatsoever
  27.  * to prevent the counter from wrapping around between reads.
  28.  */
  29. READ_HANDLER( centiped_IN0_r )
  30. {
  31.     static int oldpos,sign;
  32.     int newpos;
  33.  
  34.     newpos = readinputport(6);
  35.     if (newpos != oldpos)
  36.     {
  37.         sign = (newpos - oldpos) & 0x80;
  38.         oldpos = newpos;
  39.     }
  40.  
  41.     return ((readinputport(0) & 0x70) | (oldpos & 0x0f) | sign );
  42. }
  43.  
  44. READ_HANDLER( centiped_IN2_r )
  45. {
  46.     static int oldpos,sign;
  47.     int newpos;
  48.  
  49.     newpos = readinputport(2);
  50.     if (newpos != oldpos)
  51.     {
  52.         sign = (newpos - oldpos) & 0x80;
  53.         oldpos = newpos;
  54.     }
  55.  
  56.     return ((oldpos & 0x0f) | sign );
  57. }
  58.